# MODIFY HERE
base_dir=/home/swlee/corpus/wmt06
pair=fr-en
src=en
tgt=fr
label=ef
wa_gold=no

########################################################

if [ $# == 3 ]; then
	echo -n ""
else
	echo "usage: " `basename $0` " [ st | int | uni ]  [ r | ri | rid |...]  number(k)"
	exit
fi


scripts=`pwd`/scripts

symm=$1
copyopt=$2
size=$3

train_corpus_dir=${base_dir}/train
eval_corpus_dir=${base_dir}/test-06
dev_corpus_dir=${base_dir}/dev

# eval
eval=`wc -l ${eval_corpus_dir}/${src}.low | awk '{ print $1 }'`

# dev
dev=`wc -l ${dev_corpus_dir}/${src}.low | awk '{ print $1 }'`

let train=${size}*1000
let all=${eval}+${dev}+${train}
let eval_dev=${eval}+${dev}

echo "Evaluation: " $eval
echo "Development:" $dev
echo "Training:   " $train

#### start automatic generation
dir=${label}-${symm}-${copyopt}-${size}k.ccat
echo Creating $dir
rm -rf $dir; mkdir -p $dir;
cd $dir

##### running file
ln -s ${scripts}/run-all.sh .
ln -s ${scripts}/run-smt.sh .
ln -s ${scripts}/run-copycat.sh .

##### INFO
mkdir info
cd info
#ln -s $corpus/wa-gold.gui.giza  wa-gold.ans
#ln -s $corpus/wa-gold.num wa-gold.nao
echo ${eval} > num-eval.var
echo ${dev} > num-dev.var
echo ${train} > num-train.var
echo ${symm} > symm.var
echo ${copyopt} > copyopt.var
echo ${label} > lang.var
echo ${wa_gold} > wa-gold.var
cd ..

##### Init
mkdir i0; cd i0;
ln -s ${scripts}/copycat.sh .
ln -s ${scripts}/copycat-train.sh .
ln -s ${scripts}/make-next.sh .
echo 0 > now-itr.var


### Corpus
# Corpus consists of three parts: train, dev, and eval.
# If the gold-standard judgment of wa is available (ek), giza is needed to be run with eval + dev + train. 
mkdir corpus; cd corpus;
ln -s ${eval_corpus_dir}/${src}.low ./src-eval.tok
ln -s  ${dev_corpus_dir}/${src}.low ./src-dev.tok
head -${train} ${train_corpus_dir}/${pair}.low.${src} > ./src-train.tok
cat src-eval.tok src-dev.tok src-train.tok > src-all.tok

ln -s ${eval_corpus_dir}/${src}.keep.parse ./src-eval.parse
ln -s  ${dev_corpus_dir}/${src}.keep.parse ./src-dev.parse
head -${train} ${train_corpus_dir}/${pair}.keep.${src}.parse > ./src-train.parse
cat src-eval.parse src-dev.parse src-train.parse > src-all.parse

ln -s ${eval_corpus_dir}/${tgt}.low ./tgt-eval.tok
ln -s  ${dev_corpus_dir}/${tgt}.low ./tgt-dev.tok
head -${train} ${train_corpus_dir}/${pair}.low.${tgt} > ./tgt-train.tok
cat tgt-eval.tok tgt-dev.tok tgt-train.tok > tgt-all.tok
cd ..


### WA
mkdir wa; cd wa;
if [ ${wa_gold} == "no" ]; then
	ln -s ../corpus/src-train.tok src.tok
	ln -s ../corpus/tgt-train.tok tgt.tok
else
	ln -s ../corpus/src-all.tok src.tok
	ln -s ../corpus/tgt-all.tok tgt.tok
fi

ln -s ${scripts}/Makefile.giza-run ./Makefile
ln -s ${scripts}/eval.sh .
ln -s ${scripts}/recov.sh .
ln -s ${scripts}/symm.sh .
cd ..;

# SMT data
mkdir smt; cd smt;
cat ${scripts}/Makefile | sed s/VARIABLE/${label}-${symm}-${copyopt}-${size}/ > Makefile
ln -s ../corpus/*.tok .
cd ..;

cd ..;
echo Done

